"""
习题 32： 循环和列表
"""

the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apriots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']

# this first kind of for-loop goes through a list
# 第一种循环是通过列表来进行的
for number in the_count:
    print("This is count %d" % number)

# same as above
# 和上面一样
for fruit in fruits:
    print("A fruit of type: %s" % fruit)

# aslo we can go through mixed lists too
# notice we have to use %r since we don't know what's in it
# 我们也可以通过复合列表来循环
# 注意这次我们要用 %r, 因为我们不知道里面是什么
for i in change:
    print("I got %r" % i)


# we can also build lists, first start with an enmpty one
# 我们也可以从一个空白的列表开始
elements = []

# then use the range function to do 0 to 5 counts
# 然后用 range 函数来从 0 到 5 循环
for i in range(0, 6):
    print("Adding %d to the list." % i)
    # append is a function that lists understand
    # append 是一个列表能够理解的函数
    elements.append(i)

# now we can print them out too
# 现在我们可以把他们打印出来了
for i in elements:
    print("Element was： %d" % i)




